﻿using SwenAssigment.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SwenAssigment
{
    public partial class AccRequest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridView1.DataSource = JcUser.GetAllRequest(-1, "");
                GridView1.DataBind();
            }
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int index = e.RowIndex;
            JcUser.DeletedRequest(Convert.ToInt32(GridView1.DataKeys[index].Values[0].ToString()));
            GridView1.DataSource = JcUser.GetAllRequest();
            GridView1.DataBind();
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridView row = (GridView)sender;
            //sender = object of control
            // In this example, the first column (index 0) contains
            //TextBox1.Text = row.Cells[9].Text;
            JcUser.UpdateRequest(Convert.ToInt32(GridView1.DataKeys[GridView1.SelectedIndex].Values[0].ToString()), ((DropDownList)row.Rows[GridView1.SelectedIndex].FindControl("DropDownList1")).SelectedItem.Text.ToString());
            GridView1.DataSource = JcUser.GetAllRequest();
            GridView1.DataBind();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            GridView1.DataSource = JcUser.GetAllRequest(1, TextBox2.Text);
            GridView1.DataBind();
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            GridView1.DataSource = JcUser.GetAllRequest(0, TextBox3.Text);
            GridView1.DataBind();
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            GridView1.DataSource = JcUser.GetAllRequest(1, DropDownList2.SelectedValue.ToString());
            GridView1.DataBind();
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            GridView1.DataSource = JcUser.GetAllRequest(-1, "");
            GridView1.DataBind();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataBind();
        }
    }
}